-- trap
-- created by panyl
-- 地牢格子：陷阱

return {
    restoreGrid = function(grid, info)
        -- 还原次数
        if type(info["times"]) == "number" then
            grid.times = info["times"];
        end
        -- 还原奖励
        if info.bonus then
            grid.bonus = info["bonus"];
            info["bonus"] = nil;
        end
    end,

    -- 收集上下文
    collectContext = function(grid)
        -- 收集已使用次数
        return { ["times"] = grid.times, ["bonus"] = grid.bonus};
    end,

    -- 自动战斗
    autoFight = function(grid)
        local pos = grid:getPos();
        local trapId = grid.id;

        local aliveMonsters = AutoFightM.getData()["aliveMonsters"];
        if not aliveMonsters or #aliveMonsters <= 0 then
            -- 没怪物
            return false;
        end

        if CommonTrapM.checkAction(trapId, pos) then
            -- 发动陷阱
            return DungeonActionM.go("trap_action", pos);
        end
        return false;
    end,
};
